package com.vtb.thread;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.vtb.base.VtbDaoFactory;
import com.vtb.dao.impl.OtDaoImpl;
import com.vtb.entity.DataCache;
import com.vtb.entity.MessageCount;
import com.vtb.entity.Var;
import com.vtb.utils.JdbcUtils;

/**
 * 每二十分钟记录一次消息转发数量
 *
 * @author Chen Tao
 * @date 2012-7-1 下午06:58:07
 */
public class CountWriteThread implements Runnable{
	private static final Log log = LogFactory.getLog(CountWriteThread.class);
	private MessageCount messageCount = new MessageCount();
	OtDaoImpl otDao = (OtDaoImpl) VtbDaoFactory.getInstance().getDao(Var.OTDAO);
	public void run() {
		log.info("数量记录线程已启动");
		while (true) {
			try {
				Thread.sleep(1000*60*20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			int count = DataCache.getMcount();
			messageCount.setUni("count");
			messageCount.setPara(String.valueOf(count));
			try {
				otDao.update(messageCount);
				JdbcUtils.commit();
			} catch (Exception e) {
				JdbcUtils.rollback();
			}finally{
				JdbcUtils.close();
			}
		}
	}

}
